<template>
	<div class="main">
		<div class="content">
			<div class="center">
				<div class="user">
					<div>用户名:</div>
					<div class="alter">{{studentData.acctno}}</div>
				</div>
				<div class="user">
					<div>新密码:</div>
					<input class="alter" type="password" v-model="studentData.newPasswd" maxlength="20" placeholder="请输入新密码"/>
				</div>
				<div class="user">
					<div>确认密码:</div>
					<input class="alter" type="password" maxlength="20" v-model="studentData.okPasswd" placeholder="请再次确认新密码"/>
				</div>
			</div>
		</div>
		<div @click="ajaxUpdateStudent" class="submit">确定</div>
	</div>
</template>
<script>
import router from '@/router/index'
import { studentFindStudentById,studentUpdateStudentById } from '@/api/student'
import jsMd5 from 'js-md5'

export default {
	components: {
		
	},
	data() {
		return {
			baseUrl:process.env.VUE_APP_BASE_API,
			baseUrl:process.env.VUE_APP_BASE_API,
			studentData:{
				acctno:"",
				newPasswd:"",
				okPasswd:""
			}
		}
	},
	created:async function() {
		var ajaxData = {}
		var resultData = await studentFindStudentById(ajaxData)
		if(resultData.code==200){
			this.studentData.acctno=resultData.data.acctno
		}
	},
	beforeMount: function() {
		
	},
	mounted: function() {
		
	},
	methods: {
		ajaxUpdateStudent:async function() {
			if(!this.studentData.newPasswd||this.studentData.newPasswd.length<6){
				alert("请填写新密码且不得低于6位");
				return;
			}
			if(!this.studentData.okPasswd||this.studentData.okPasswd.length<6){
				alert("请填写确认密码且不得低于6位");
				return;
			}
			if(this.studentData.newPasswd!=this.studentData.okPasswd){
				alert("新密码与确认密码不一致");
				return;
			}
			var ajaxData = {}
			ajaxData.passwd = jsMd5(this.studentData.newPasswd)
			var resultData = await studentUpdateStudentById(ajaxData)
			if(resultData.code==200){
				alert("修改成功,请重新登录")
				router.replace({path:"/wechat/studentlogin"});
			}else{
				alert("修改失败")
			}
			this.ajaxFlag = true;
		}
	}
}
</script>
<style lang="scss" scoped>
	.main{
		width: 100%;
		height: 100vh;
		overflow: auto;
		background: #F4F4F4;
		.content{
			width:100%;
			//height:400px;
			background:#FFFFFF;
			border-radius: 20px;
			overflow: hidden;
			.center{
				margin-left:18px;
				margin-right: 18px;
				.user{
					margin-top:35px;
					padding-bottom: 20px;
					display: flex;
					border-bottom: 1px solid #C4C2C2; 
					>div:nth-child(1){
						margin-right:31px;
						font-size: 12px;
						font-weight: 400;
						color: #000000;
					}
					.alter{
						font-size: 12px;
						font-weight: 400;
						color: #255EAC;
					}
					>input{
						color:#000000 !important;
						width:60%;
						border:none;
						outline:none;
					}
				}
				>.user:nth-last-child(1){
					border-bottom: none;
					>div:nth-child(1){
						margin-right:18px;
					}
				}
			}
		}
		.submit{
			margin-left:17px;
			margin-right:20px;
			line-height:32px;
			font-size: 16px;
			font-weight: 400;
			color: #FBFBFB;
			background: #6AA5EB;
			text-align: center;
			margin-top:33px;
		}
		
	}
</style>